<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once('base_mapper.php');
Class Administer_mapper extends Base_mapper{

	protected $object_class = 'administer_object';
	
	protected $table = 'administers';
	
	protected $primary_key = 'id';
	
	public function validate_user($username, $password){
		$this -> db -> select('*');
		$this -> db -> from($this->table);
		$this -> db -> where('username = ' . "'" . $username . "'");
		$this -> db -> where('password = ' . "'" . MD5($password) . "'");
		$this -> db -> limit(1);

		$query = $this -> db -> get();
		if($query -> num_rows() == 1)
		{
			$data = $query->result();
			return $this->buildObject($data[0]);
		}
		else
		{
			return false;
		}
		
	}
	protected function doBuildObject($row){
		return new Administer_object($row->id, $row->username, $row->password, $row->user_level);
	}
	protected function doInsert($obj){
		throw new Exception("overwrite the insert" . get_class($this));
	}
	protected function doUpdate($obj){
		throw new Exception("overwrite the update" . get_class($this));
	}
}